package com.haitaoit.chengquan.module.center.adapter.xuqiu;

import android.content.Context;
import android.graphics.Color;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.text.style.RelativeSizeSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.haitaoit.chengquan.R;
import com.haitaoit.chengquan.base.BackCall;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;

import java.util.List;

/**
 * Created by Administrator on 2016/10/12.
 */
public class MyXuqiuItemAdapter extends BaseAdapter {
    private Context context;
    private BackCall backCall;
    private List list;

    public void setBackCall(BackCall backCall) {
        this.backCall = backCall;
    }

    public MyXuqiuItemAdapter(Context context) {
        this.context = context;
    }

    public List getList() {
        return list;
    }

    public void setList(List list) {
        this.list = list;
    }

    @Override
    public int getCount() {
//        return list == null ? 0 : list.size();
        return 2;
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, final ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.my_yuyue_item2, null);
            holder = new ViewHolder();
            ViewUtils.inject(holder, convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        // 部分字体变大变色
        SpannableString msp = new SpannableString("参考价格：¥ 0.0");
        msp.setSpan(new ForegroundColorSpan(Color.BLACK), 0, 5, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        msp.setSpan(new RelativeSizeSpan(1.5f), 6, "参考价格：¥ 0.0".length(),
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        holder.yuyue_money.setText(msp);

        return convertView;
    }

    class ViewHolder {
        @ViewInject(R.id.yuyue_money)
        TextView yuyue_money;
    }
}
